﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class admin_pwd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    //提交处理
    public void pwd(object sender, EventArgs e)
    {
        string oldpass = Request["oldpass"].ToString();
        string newpass = Request["newpass"].ToString();
        OleDbConnection conn = DB.conn();
        OleDbCommand comm = null;
        try
        {
            //判断原密码是否正确
            if (conn != null && Session["admin"]!=null)
            {
                conn.Open();
                comm = new OleDbCommand();
                comm.Connection = conn;
                comm.CommandText = "select * from admin where admin='"+Session["admin"].ToString()+"' and password='"+MD5.String2MD5(oldpass)+"'";
                OleDbDataReader reader = comm.ExecuteReader();
                if (reader != null & reader.HasRows)
                {
                    reader.Close();
                    //更新密码
                    comm.Dispose();
                    comm.Connection = conn;
                    comm.CommandText = "update admin set [password]='"+MD5.String2MD5(newpass)+"' where admin='"+Session["admin"].ToString()+"'";
                    comm.ExecuteNonQuery();
                    Response.Write("<script>alert('修改成功！');</script>");
                }
                else
                {
                    Response.Write("<script>alert('原密码不正确！');</script>");
                }
            }
        }
        catch (Exception error)
        {
            Response.Write(error.ToString());
        }
        finally {
            if (comm != null) {
                comm.Dispose();
            }
            conn.Close();
        }
    }
}
